import {getTopList, getPlaylistDetail, getPlaylistHot, getSongList, getSimiSong} from "@/api/home/index"

import {geSimiPlaylist} from "../../api/song_list/index.js";


const musicListState = {
  noShowMvPlayCon: false // 在mv页面不显示播放控件
}
const musicListAction = {
  // 获取榜单集合，飙升榜，新歌榜，原创榜
  getTopList() {
    return getTopList().then(res => {
      const {code, list} = res
      if (Number(code) === 200) {
        // console.log(list)
        return list
      }
    })
  },
  // 获取榜单详情
  getRankingListDetail(id) {
    return getPlaylistDetail(id).then(res => {
      if (Number(res.code) === 200)
      return res
    })
  },
  // 热门推荐标题，默认返回10条
  getPlaylistHot(num) {
    return getPlaylistHot(num).then(res => {
      const {code, tags} = res
      if (Number(code) === 200) {
        if(num) {
          return tags.slice(0, num)// 获取前五条数据
        } else {
          return tags
        }
      }
    })
  },
  // 首页热门推荐数据
  getSongList() {
    return getSongList().then(res => {
      const {code, result} = res
      if (Number(code) === 200) {
        return result
      }
    })
  },
  // 相似歌曲
  getSimiSong(id) {
    return getSimiSong(id).then(res => {
      const { code, songs } = res
      if (Number(code) === 200) {
        return songs
      }
    })
  },
  // 获取包含这首歌的歌单
  geSimiPlaylist() {
    return geSimiPlaylist(this.currentInfo.id).then(res => {
      const { code, playlists } = res
      // console.log(res)
      if (Number(code) === 200) {
        return playlists
      }
      // console.log(res)
    })
  }
}


const musicListGetter = {

}

export {
  musicListState,
  musicListAction,
  musicListGetter
}
